//
//  MBProgressHUD+Hud.m
//  InsuranceMarketing
//
//  Created by initial on 2018/1/25.
//  Copyright © 2018年 initial. All rights reserved.
//

#import "MBProgressHUD+Hud.h"

@implementation MBProgressHUD (Hud)
+(void)showLoadingView:(UIView *)view{
    
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.mode = MBProgressHUDModeIndeterminate;
    hud.label.text = @"请稍等...";
}


+(void)showLoadingView:(UIView*)view andText:(NSString*)tipText{
    
    
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.mode = MBProgressHUDModeIndeterminate;
    hud.label.text = tipText;
}

+(void)showLoadingView:(UIView *)view andText:(NSString *)tipText andOffsetY:(CGFloat)offsety{
    
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    //是否有遮罩
    hud.backgroundColor=[UIColor clearColor];
    hud.label.text=tipText;
}

+(void)hideLoadingView:(UIView *)view{
    
    [MBProgressHUD hideHUDForView:view animated:YES];
}

+(void)showDoneWith:(UIView*)view isSucess:(Boolean)isSucess completion:(void(^)(void))completion{
    
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    
    hud.mode = MBProgressHUDModeCustomView;
    UIImage *image;
    if(isSucess){
        image = [[UIImage imageNamed:@"Checkmark"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        hud.label.text = NSLocalizedString(@"保存成功", @"");
    }else{
        image = [[UIImage imageNamed:@"Checkmark_wrong"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        hud.label.text = NSLocalizedString(@"保存失败", @"");
    }
    
    hud.customView = [[UIImageView alloc] initWithImage:image];
    
    hud.square = YES;
    
    [hud hideAnimated:YES afterDelay:3.f];
    dispatch_time_t delayTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(4.f * NSEC_PER_SEC));
    dispatch_after(delayTime, dispatch_get_main_queue(), ^{
        if(completion){
            completion();
        }
        
    });
    
}

+(void)showDoneWith:(UIView*)view tilte:(NSString*) title isSucess:(Boolean)isSucess completion:(void(^)(void))completion{
    
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    
    hud.mode = MBProgressHUDModeCustomView;
    UIImage *image;
    if(isSucess){
        image = [[UIImage imageNamed:@"Checkmark"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        hud.label.text = NSLocalizedString(title, @"");
    }else{
        image = [[UIImage imageNamed:@"Checkmark_wrong"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        hud.label.text = NSLocalizedString(title, @"");
    }
    
    hud.customView = [[UIImageView alloc] initWithImage:image];
    
    hud.square = YES;
    
    [hud hideAnimated:YES afterDelay:3.f];
    dispatch_time_t delayTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(4.f * NSEC_PER_SEC));
    dispatch_after(delayTime, dispatch_get_main_queue(), ^{
        if(completion){
            completion();
        }
        
    });
    
}



@end
